//
//  ViewController.swift
//  MySwiftPullToRefresh
//
//  Created by likai on 2017/5/2.
//  Copyright © 2017年 terry. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    var scrollView : UIScrollView = UIScrollView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height))
    
    
    
    var style : Style = .indicatorHeader
    
    
    var myView:UIView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: 2 * UIScreen.main.bounds.size.height))
    
    
    
    
    

    override func viewDidLoad() {
        super.viewDidLoad()
        
        myView.backgroundColor = UIColor.brown
        
        view.addSubview(scrollView)
        
        scrollView.addSubview(myView)
        
        scrollView.contentSize = CGSize(width: UIScreen.main.bounds.width, height: 2 * UIScreen.main.bounds.size.height)
        
        scrollView.bounces = true
        
        scrollView.backgroundColor = UIColor.gray
        
        
        
        
        
        
        scrollView.spr_addIndicatorHeader { [weak self] in
            DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: {
                self?.scrollView.spr_endRefreshing()
            })
        }
//        scrollView.spr_addTextHeader() { [weak self] in
//            DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: { 
//                self?.scrollView.spr_endRefreshing()
//            })
//            
//            
//        }

//        guard let url = Bundle.main.url(forResource: "demo-small", withExtension: "gif"), let data = try? Data(contentsOf: url) else { return }
//        scrollView.spr_addGIFHeader(data: data, isBig: false, height: 60) { [weak self] in
//            DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: { 
//                self?.scrollView.spr_endRefreshing()
//            })
//            
//        }
        
//        guard let url = Bundle.main.url(forResource: "demo-small", withExtension: "gif"), let data = try? Data(contentsOf: url) else { return }
//        
//        scrollView.spr_addGIFTextHeader(data: data) { 
//            DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: { 
//                self.scrollView.spr_endRefreshing()
//            })
//        }
        
//        guard let url = Bundle.main.url(forResource: "demo-big", withExtension: "gif"), let data = try? Data(contentsOf: url) else { return }
//        
//        scrollView.spr_addGIFHeader(data: data, isBig: true, height: 120) { 
//            DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: { 
//                
//                self.scrollView.spr_endRefreshing()
//            })
//        }
        
        
//        scrollView.spr_addSuperCarHeader { [weak self] in
//            DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: { 
//                self?.scrollView.spr_endRefreshing()
//            })
//            
//        }
        
        
        
//        switch style {
//        case .indicatorHeader:
//            scrollView.spr_addIndicatorHeader { [weak self] in
//                DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: { 
//                    self?.scrollView.spr_endRefreshing()
//                })
//            }
//         
//        default :
//            print("as")
//            
//        }
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        
    }
    


}

extension ViewController{
    
    enum Style : Int {
        case indicatorHeader, textHeader, smallGIFHeader, gifTextHeader, bigGIFHeader, superCatHeader, indicatorFooter, textFooter
    }
}
